from django.db import models


class Books(models.Model):
    sex_choice = (
        (0, '男'),
        (1, '女'),
    )
    book_name = models.CharField(max_length=30, verbose_name='图书名')
    author = models.CharField(max_length=30, verbose_name='作者')
    sex = models.SmallIntegerField(choices=sex_choice, verbose_name='性别')
    price = models.FloatField(verbose_name='价格')
    isbn = models.CharField(max_length=30, verbose_name='ISBN', null=False)
    pubish_date = models.DateField(verbose_name='出版日期', auto_now=True)

    def __str__(self) -> str:
        return "<%s, %s>" % (self.book_name, self.author)

    class Meta:
        db_table = 'books'


class Author(models.Model):
    author = models.CharField(max_length=30, verbose_name='作者')
    age = models.IntegerField(verbose_name='年龄')
    occupation = models.CharField(
        max_length=30, verbose_name='职业', default='无业')

    class Meta:
        db_table = 'author_info'
